home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)win_events.c V1.28 3/13/95";
- #endif
- /*
- | file name - win_events.c
- |===================================================================
- |
- | This program demonstrates how to use the window event routines
- | to gather events from a DataViews window. It uses
- | VOloWinEventPoll, which gets the next event from the queue.
- | Also, it shows how a typical application might respond to
- | some of the new event types such as V_RESIZE, V_EXPOSE, and
- | V_WINDOW_QUIT.
- |
- | Events are passed to our event request handler so the input
- | objects will update. In this example, the graphs are updated
- | only if the input object took user input.
- |
- | In addition, this example shows how to specify the dimensions
- | and name of a window created using TscOpenSet. If you want
- | to see a summary of the events to standard output as they
- | occur, rename the executable "win_eventsdb.x" and invoke it
- | from the command line.
- |
- | Generate a window QUIT event or type <q|Q> to exit.
- |
- |
- |===================================================================
- */
- #include <windows.h>
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VUerfundecl.h" /* VUer routines (event handling routines) */
- #include "GRfundecl.h" /* GR routines (interface to display device) */
- #include "VUfundecl.h" /* VU routines (utilities) */
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define VIEW_NAME "multi1.v"
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define DRAWING_VIEWPORT (RECTANGLE *)NULL
- #define WIN_EVENTS_DBG "win_eventsdb.x"
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
- /*
- * program arguments
- * argv[1] - display device (default is DVDEVICE)
- */
-
- /* Define & initialize device name and view filename */
- char *device_name = DVDEVICE; /* default device name */
- char *view_name = VIEW_NAME; /* default view name */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
- DRAWPORT drawport; /* how & where to display picture, picture
- frame */
- VIEW view; /* picture representation of the view file */
-
- /* Control loop variables */
- OBJECT location; /* the event representation */
- WINEVENT *we; /* structure storing details of event */
- int event_req_status; /* status of event requests */
-
- /* Other variables */
- int screenx, /* new width of window in pixels */
- screeny; /* new height of window in pixels */
- int Quit = NO; /* flag to quit program */
-
-
- /*-----------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- make_argv(&argc,&argv,GetCommandLine());
- TInit( DVPATH, DISPFORMS_STB );
-
- /*
- * TscOpenSet: opens a device as a screen object using
- * specified attributes
- *
- * Set exposure block to YES to insure the window
- * is ready for drawing when TdpDraw is called.
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_WINDOW_NAME, "win_events",
- V_WINDOW_WIDTH, 400,
- V_WINDOW_HEIGHT, 400,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_KEYRELEASE |
- V_BUTTONPRESS | V_BUTTONRELEASE |
- V_ENTERNOTIFY | V_MOTIONNOTIFY | V_LEAVENOTIFY |
- V_EXPOSE | V_RESIZE | V_WINDOW_QUIT,
- (ULONG) 0);
-
- /*
- * TviLoad: Load a view in from a file,
- * user supplied view or default view of multi1.v
- * TdpCreate: Create a drawport.
- * The drawport is attached to the screen object
- * specified while view specifies the view to be
- * displayed on the screen.
- */
- view = TviLoad (view_name);
- if (!view)
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", view_name);
- S_EXIT (EXIT_ERR);
- }
- drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
-
- /*
- * TscErase: Erase the entire screen in the default
- * background color
- * TdpDraw: Draw the contents of the drawport
- */
- TscErase (screen);
- TdpDraw (drawport);
-
-
- /*--------------------
- * Control loop
- *
- * Poll the event queue for window events specified by the
- * window mask. Handle each of the events as they happen.
- * Events occurring within input objects will be handled
- * through the event request handler VUerHandleLocEvent.
- * Updates are performed if an input object used the
- * the event.
- */
- FOREVER
- {
- /*
- * VOloWinEventPoll: Polls for the next window event.
- * The polling mode used is V_WAIT.
- * Therefore, VOloWinEventPoll does not
- * return until a masked event is
- * generated. V_WAIT always produces
- * a valid location object.
- */
- location = VOloWinEventPoll (V_WAIT);
-
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
-
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_RESIZE:
- /*
- * The window size has been changed.
- * TscReset: Resets all screen drawports after
- * window resizing
- * GRaspect_ratio: Gets the size of the screen in pixels
- *
- * Print the new size of the window to standard output.
- */
- TscReset (screen);
- GRaspect_ratio (&screenx, &screeny);
- printf ("Window Size: %d %d\n", screenx, screeny);
- break;
-
- case V_WINDOW_QUIT:
- /*
- * User requests a window quit.
- * Print message for quitting after V_WINDOW_QUIT
- */
- printf ("Quitting...\n");
- Quit = YES;
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- * VOloKeySym: Returns the key symbol value of the
- * location object
- * If the key symbol represents the characters 'q'
- * or 'Q' then quit the program.
- */
- switch (VOloKeySym (location))
- {
- case 'q':
- case 'Q':
- Quit = YES;
- break;
-
- default:
- break;
- }
- break;
-
- case V_KEYRELEASE:
- case V_BUTTONPRESS:
- case V_BUTTONRELEASE:
- case V_MOTIONNOTIFY:
- /*
- * VUerHandleLocEvent: Service the event.
- * This routine will check if the
- * event is used by any input objects
- * that are in the view.
- */
- event_req_status = VUerHandleLocEvent (location);
-
- /*
- * Update view only if an input object used the event
- * TdpDrawNext: Update all dynamic objects within a
- * drawport's view.
- */
- if (event_req_status != INPUT_UNUSED)
- TdpDrawNext (drawport);
- break;
-
- default:
- break;
- }
-
- /*
- * VOloWinEventGet: Returns the window event structure of
- * the location object.
- * VUweReportEvent: Reports window events at a specified
- * level of detail. Level 3 reports
- * information relevant to the event type.
- *
- * To report window event information, rename the executable
- * image of "win_events.x" to "win_eventsdb.x". Invoke this
- * executable from the command line.
- */
- if (!strcmp (argv[0], WIN_EVENTS_DBG))
- {
- we = (WINEVENT *) VOloWinEventGet (location);
- VUweReportEvent (we, 3);
- printf ("\n");
- }
-
- /* exit the program */
- if (Quit == YES)
- break;
- }
-
-
- /*--------------------
- * Termination
- *
- * TscErase: Erase the entire screen in the default
- * background color
- * TdpDestroy: Destroy the drawport,
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscCloseCurrentScreen: Close the current display screen
- * TTerminate: Perform the clean-up for DV-Tools
- */
- TscErase (screen);
- TdpDestroy (drawport);
- TviDestroy (view);
- TscCloseCurrentScreen ();
- TTerminate ();
- return EXIT_OK;
- }
-